import { defineConfig, loadEnv } from 'vite'
import vue from '@vitejs/plugin-vue'
import path from 'path'

export default defineConfig(({ mode }) => {
  // 加载所有环境变量（包括没有VITE_前缀的）
  const env = loadEnv(mode, process.cwd(), '')
  
  console.log('API Base URL:', env.VITE_API_BASE_URL || env.API_BASE_URL)
  console.log(env.VUE_APP_GOOGLE_MAP_KEY)
  return {
    plugins: [vue()],
    resolve: {
      alias: {
        '@': path.resolve(__dirname, './src'),
        'components': path.resolve(__dirname, './src/components'),
      }
    },
    server: {
      proxy: {
        '/api': {
          target: env.VITE_API_BASE_URL || '', // 默认回退地址
          changeOrigin: true,
          rewrite: (path) => path.replace(/^\/api/, ''),
        }
      }
    }
  }
})